﻿@page
@using SXFramWork.Web
@{
    ViewData["Title"] = "修改密码";
    Layout = AdminLayout.Pjax(HttpContext);
}

<h3 style="background-color:#d9edf7;color:#555;width:400px;margin-left:40px; font-size:16px;margin-top:20px;">修改密码后会重新验证身份信息</h3>
<form class="layui-form" action="" style="margin-top:10px;">
    <div class="layui-form-item">
        <label class="layui-form-label">当前密码</label>
        <div class="layui-input-block">
            <input type="password" style="width:300px;" name="oldpwd" lay-verify="required" autocomplete="off" lay-reqtext="当前密码不能为空" placeholder="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-block">
            <input type="password" style="width:300px;" name="newpwd" lay-verify="required" lay-reqtext="新密码不能为空" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block">
            <input type="password" style="width:300px;" name="surepwd" lay-verify="required" lay-reqtext="确认密码不能为空" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="submit">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

    <script>
        layui.use(['layer', 'jquery', 'common', 'form'], function () {
            var form = layui.form, $ = layui.$, os = layui.common;
            os.chageRoutePath('个人中心/修改密码');
            //监听提交
            form.on('submit(submit)', function (data) {
                $('#submit').attr('disabled', true).find('i').removeClass('layui-hide');
                if (data.field.newpwd != data.field.surepwd) {
                    os.error("新密码和确认密码不一致");
                    return false;
                }
                var urls = "api/admin/sysuser/editpwd";
                os.ajax(urls, data.field, function (res) {
                    $('#submit').attr('disabled', false).find('i').addClass('layui-hide');
                    if (res.code == 1) {
                        os.success("修改成功,将进行重新登录");
                        //执行退出
                        setTimeout(loginout, 1000);
                    } else {
                        os.error(res.msg);
                    }
                },'post');
                return false;
            });
        });
        //退出
        function loginout() {
            os.load();
            //清除缓存的登录信息
            os.SessionRemove("authinfo");
            localStorage.removeItem("access_token");
            window.location.href="/admin/login"
        }
    </script>


